/**
 * @class   wosh::entertainment::MediaList
 * @brief   
 *
 * PlayList of MediaTrack
 * used inside Palyers devices too!?
 *
 ****************************************************************************
 * @version $Id: MediaList.h 2863 2010-08-07 04:28:58Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Entertainment_MediaList_H__
 #define __WOSH_Entertainment_MediaList_H__

 #include <woshDefs.h>
 #include <core/Containers.h>
 #include <core/Object.h>
 #include <core/PropertiesProvider.h>

 #include <framework/entertainment/MediaTrack.h>


namespace wosh {
 class List;
 class Table;
 template <class T> class DataFieldCollector;
 namespace entertainment {

 #define _MediaList_KEY_CurrentIndex	"CurrentIndex"
 #define _MediaList_KEY_CurrentPosition	"CurrentPosition"
 #define _MediaList_KEY_	""


class MediaList : public Object
 {
	WOSH_SERIALIZABLE(wosh::entertainment::MediaList)
	WOSH_COMPARE_RTTI(wosh::entertainment::MediaList)

	typedef ListT<wosh::entertainment::MediaTrack*> tMediaTrackList;


	public:
		/**
		 * @brief   Default constructor. Init vars.
		 */
		MediaList();
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		MediaList( const MediaList& m );
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~MediaList() { }

	public:

		void clear();

		WRESULT remove( int index );

		List* toList() const;
		Table* toTable() const;

//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:
		void setCurrentIndex( int value );
		void setCurrentPosition( long value );

		void setCurrentTrack( const ResourcePath& fullpath );

		inline void setArtist( const std::string& artist )		{ Properties.set( _MediaTrack_KEY_Artist, artist ); }
		inline void setAlbum( const std::string& album )		{ Properties.set( _MediaTrack_KEY_Album, album ); }
		inline void setGenre( const std::string& gerne )		{ Properties.set( _MediaTrack_KEY_Genre, gerne ); }
		inline void setLength( unsigned long seconds )			{ Properties.set( _MediaTrack_KEY_Length, Variant_TS(seconds*1000) ); }

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:
//		long getID() const									{ return this->id; }
//		long getTimeStamp() const							{ return this->timestamp; }

		inline const tMediaTrackList& getTracks() const			{ return this->tracks; }
		inline tMediaTrackList& getTracks()						{ return this->tracks; }

		inline int getCurrentIndex() const						{ return this->currentIndex; }
		inline long getCurrentPosition() const					{ return this->currentPosition; }

		inline bool isIndexInRange() const						{ return !( this->currentIndex < 0 || this->currentIndex > (int)this->tracks.size() ); }
		inline bool isLastTrack() const							{ return ( this->currentIndex+1 >= (int)this->tracks.size() ); }

		MediaTrack* getCurrentTrack();

		inline const wosh::PropertiesProvider& getProperties() const { return this->Properties; }
		inline wosh::PropertiesProvider& getProperties()		{ return this->Properties; }


		inline int size() const									{ return this->tracks.size(); }

		bool hasNext() const;

		static DataFieldCollector<MediaList>* getDataFields();

//@}
/** @name Operators Overloading
 * @{
 ******************************************************************************/
	public:
		virtual MediaList& operator=(const MediaList& m);
		virtual bool operator==(const MediaList &other) const;

//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual std::string toString() const			{ return ""; }
		virtual bool updateHash( DataHashContext* hash_context ) const;
//@}
/** @name Internal vars
 * @{
 ******************************************************************************/
	protected:
		tMediaTrackList tracks;
		int currentIndex;
		long currentPosition;

		wosh::PropertiesProvider Properties;

//@}


}; // class def

 }; // namespace entertainment
}; // namespace wosh


#endif //__WOSH_Entertainment_MediaList_H__
